package cn.wolfcode.p2p.mgrsite.controller;

import cn.wolfcode.p2p.base.domain.SystemDictionaryItem;
import cn.wolfcode.p2p.base.excetion.DisplayableExcetion;
import cn.wolfcode.p2p.base.query.SystemDictionaryItemQueryObject;
import cn.wolfcode.p2p.base.service.ISystemDictionaryItemService;
import cn.wolfcode.p2p.base.service.ISystemDictionaryService;
import cn.wolfcode.p2p.base.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class SystemDictionaryItemController {

    @Autowired
    private ISystemDictionaryService dictionaryService;
    @Autowired
    private ISystemDictionaryItemService itemService;
    @RequestMapping("systemDictionaryItem_list")
    public String systemDictionary(@ModelAttribute("qo")SystemDictionaryItemQueryObject qo, Model model){
        model.addAttribute("systemDictionaryGroups",dictionaryService.selectAll());
        model.addAttribute("pageInfo",itemService.queryPage(qo));
        return "/systemdic/systemDictionaryItem_list";
    }


    @RequestMapping("systemDictionaryItem_update")
    @ResponseBody
    public AjaxResult saveOrUpdate(SystemDictionaryItem dictionary){
       AjaxResult result = null;
       try {
           itemService.save(dictionary);
           result = new AjaxResult();
       } catch (DisplayableExcetion e) {
           e.printStackTrace();
           result = new AjaxResult(false, e.getMessage());
       } catch (Exception e) {
           e.printStackTrace();
           result = new AjaxResult(false,"系统出错,请联系管理员");
       }
       return result;
    }



}
